package com.mdb.open.trade.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitConfig {

    public final static String REDIS_KEY_PREFIX = "mdb.tf.rabbit";


    /**
     * 客户队列交换
     */
    public final static String EXCHANGE_CUSTOMER = "customerExchange";

//    public final static String TF_WEB_LOAN_REMIT_START = "tf_web_loan_remit_start_local";
//    public final static String TF_WEB_LOAN_REMIT_UPDATE = "tf_web_loan_remit_update_local";
//    public final static String TF_WEB_OUT_REMIT_START = "tf_web_out_remit_start_local";
//    public final static String TF_WEB_OUT_REMIT_UPDATE = "tf_web_out_remit_update_local";
//    public final static String TF_WEB_REPAYMENT_GET_INTEREST = "tf_web_repayment_get_interest_local";
//    public final static String TF_WEB_INWARD_CLAIM_PROCESS = "tf_web_inward_claim_process_local";
//    public final static String TF_WEB_INWARD_CLAIM_SINGLE_PROCESS = "tf_web_inward_claim_single_process_local";
//    public final static String TF_WEB_REPAYMENT_START = "tf_web_repayment_start_local";
//    public final static String TF_WEB_REPAYMENT_UPDATE = "tf_web_repayment_update_local";
//    public final static String TF_WEB_TRANSFER_START = "tf_web_transfer_start_local";
//    public final static String TF_WEB_TRANSFER_UPDATE = "tf_web_transfer_update_local";


    /**
     * 贸易融资风控模型
     */
    public final static String QUEUE_TRADE_FINANCE_RISK_MODEL = "trade.finance.risk.model";


    public final static String TF_WEB_LOAN_REMIT_START = "tf.web.loan.remit.start";

    public final static String TF_WEB_LOAN_REMIT_UPDATE = "tf.web.loan.remit.update";

    public final static String TF_WEB_OUT_REMIT_START = "tf.web.out.remit.start";

    public final static String TF_WEB_OUT_REMIT_UPDATE = "tf.web.out.remit.update";

    public final static String TF_WEB_REPAYMENT_GET_INTEREST = "tf.web.repayment.get.interest";

    public final static String TF_WEB_INWARD_CLAIM_PROCESS = "tf.web.inward.claim.process";

    public final static String TF_WEB_INWARD_CLAIM_SINGLE_PROCESS = "tf.web.inward.claim.single.process";

    public final static String TF_WEB_REPAYMENT_START = "tf.web.repayment.start";

    public final static String TF_WEB_REPAYMENT_UPDATE = "tf.web.repayment.update";

    public final static String TF_WEB_TRANSFER_START = "tf.web.transfer.start";

    public final static String TF_WEB_TRANSFER_UPDATE = "tf.web.transfer.update";

    /**
     * 融资申请
     */
    public final static String QUEUE_TRADE_FINANCE_APPLY_MODEL = "trade.finance.apply.model";
    /**
     * 贸易融资逾期通知
     */
    public final static String QUEUE_TRADE_FINANCE_OVERDUE_NOTIFY = "trade.finance.overdue.notify";
    /**
     * 贸易融资还款通知
     */
    public final static String QUEUE_TRADE_FINANCE_REPAYMENT_NOTIFY = "trade.finance.repayment.notify";

    /**
     * 商户核额
     */
    public final static String TRADE_FINANCE_MERCHANT_RISK = "trade.finance.merchant.risk";



    /**
     * 商户基本信息
     */
    public final static String MERCHANT_BASIC_INFO = "merchant.basic.info";



    public final static String TF_WEB_LOAN_REMIT_START_TOPIC = "tf.web.loan.remit.start.topic";

    public final static String TF_WEB_LOAN_REMIT_UPDATE_TOPIC = "tf.web.loan.remit.update.topic";

    public final static String TF_WEB_OUT_REMIT_START_TOPIC = "tf.web.out.remit.start.topic";

    public final static String TF_WEB_OUT_REMIT_UPDATE_TOPIC = "tf.web.out.remit.update.topic";

    public final static String TF_WEB_REPAYMENT_GET_INTEREST_TOPIC = "tf.web.repayment.get.interest.topic";

    public final static String TF_WEB_INWARD_CLAIM_PROCESS_TOPIC = "tf.web.inward.claim.process.topic";

    public final static String TF_WEB_INWARD_CLAIM_SINGLE_PROCESS_TOPIC = "tf.web.inward.claim.single.process.topic";

    public final static String TF_WEB_REPAYMENT_START_TOPIC = "tf.web.repayment.start.topic";

    public final static String TF_WEB_REPAYMENT_UPDATE_TOPIC = "tf.web.repayment.update.topic";

    public final static String TF_WEB_TRANSFER_START_TOPIC = "tf.web.transfer.start.topic";

    public final static String TF_WEB_TRANSFER_UPDATE_TOPIC = "tf.web.transfer.update.topic";

    public final static String TF_WEB_EXCHANGE = "tf.web.exchange";


    /**
     * 企查查同步事件
     */
    public final static String QUEUE_MERCHANT_SYNC_QICHACHA = "merchant.sync.qichacha";


    /**
     * 启动商户模型
     */
    public final static String QUEUE_START_MERCHANT_RISK_MODEL = "start.merchant.risk.model";



    @Bean
    TopicExchange exchange() {
        return new TopicExchange(TF_WEB_EXCHANGE);
    }

    @Bean
    public TopicExchange customerTopicExchange() {
        TopicExchange exchange = new TopicExchange(EXCHANGE_CUSTOMER);
        return exchange;
    }



    @Bean
    Binding bindingLoanRemitStartQueue(Queue loanRemitStartQueue, TopicExchange exchange) {
        return BindingBuilder.bind(loanRemitStartQueue).to(exchange).with(TF_WEB_LOAN_REMIT_START_TOPIC);
    }

    @Bean
    Binding bindingLoanRemitUpdateQueue(Queue loanRemitUpdateQueue, TopicExchange exchange) {
        return BindingBuilder.bind(loanRemitUpdateQueue).to(exchange).with(TF_WEB_LOAN_REMIT_UPDATE_TOPIC);
    }

    @Bean
    Binding bindingOutRemitStartQueue(Queue outRemitStartQueue, TopicExchange exchange) {
        return BindingBuilder.bind(outRemitStartQueue).to(exchange).with(TF_WEB_OUT_REMIT_START_TOPIC);
    }

    @Bean
    Binding bindingOutRemitUpdateQueue(Queue outRemitUpdateQueue, TopicExchange exchange) {
        return BindingBuilder.bind(outRemitUpdateQueue).to(exchange).with(TF_WEB_OUT_REMIT_UPDATE_TOPIC);
    }

    @Bean
    Binding bindingRepaymentGetInterest(Queue repaymentGetInterest, TopicExchange exchange) {
        return BindingBuilder.bind(repaymentGetInterest).to(exchange).with(TF_WEB_REPAYMENT_GET_INTEREST_TOPIC);
    }

    @Bean
    Binding bindingInwardClaimProcess(Queue inwardClaimProcess, TopicExchange exchange) {
        return BindingBuilder.bind(inwardClaimProcess).to(exchange).with(TF_WEB_INWARD_CLAIM_PROCESS_TOPIC);
    }

    @Bean
    Binding bindingInwardClaimSingleProcess(Queue inwardClaimSingleProcess, TopicExchange exchange) {
        return BindingBuilder.bind(inwardClaimSingleProcess).to(exchange).with(TF_WEB_INWARD_CLAIM_SINGLE_PROCESS_TOPIC);
    }

    @Bean
    Binding bindingRepaymentStart(Queue repaymentStart, TopicExchange exchange) {
        return BindingBuilder.bind(repaymentStart).to(exchange).with(TF_WEB_REPAYMENT_START_TOPIC);
    }

    @Bean
    Binding bindingRepaymentUpdate(Queue repaymentUpdate, TopicExchange exchange) {
        return BindingBuilder.bind(repaymentUpdate).to(exchange).with(TF_WEB_REPAYMENT_UPDATE_TOPIC);
    }

    @Bean
    Binding bindingTransferStart(Queue transferStart, TopicExchange exchange) {
        return BindingBuilder.bind(transferStart).to(exchange).with(TF_WEB_TRANSFER_START_TOPIC);
    }

    @Bean
    Binding bindingTransferUpdate(Queue transferUpdate, TopicExchange exchange) {
        return BindingBuilder.bind(transferUpdate).to(exchange).with(TF_WEB_TRANSFER_UPDATE_TOPIC);
    }

    @Bean
    Binding bindingRiskTradeApply(Queue riskTradeApply, TopicExchange exchange) {
        return BindingBuilder.bind(riskTradeApply).to(exchange).with(QUEUE_TRADE_FINANCE_APPLY_MODEL);
    }

    @Bean
    Binding bindingRiskTradeOverdue(Queue riskTradeOverdue, TopicExchange exchange) {
        return BindingBuilder.bind(riskTradeOverdue).to(exchange).with(QUEUE_TRADE_FINANCE_OVERDUE_NOTIFY);
    }

    @Bean
    Binding bindingRiskTradeRepayment(Queue riskTradeRepayment, TopicExchange exchange) {
        return BindingBuilder.bind(riskTradeRepayment).to(exchange).with(QUEUE_TRADE_FINANCE_REPAYMENT_NOTIFY);
    }

    @Bean
    Binding bindingRiskMerchant(Queue riskMerchant, TopicExchange exchange) {
        return BindingBuilder.bind(riskMerchant).to(exchange).with(TRADE_FINANCE_MERCHANT_RISK);
    }


    @Bean
    public Binding bindingStartMerchantRiskModelQueue() {
        return BindingBuilder.bind(this.startMerchantRiskModelQueue()).to(this.customerTopicExchange()).with(RabbitConfig.QUEUE_START_MERCHANT_RISK_MODEL);
    }

    @Bean
    public Queue startMerchantRiskModelQueue() {
        return new Queue(RabbitConfig.QUEUE_START_MERCHANT_RISK_MODEL);
    }

    @Bean
    public Queue merchantSyncQichachaQueue() {
        return new Queue(RabbitConfig.QUEUE_MERCHANT_SYNC_QICHACHA);
    }

    @Bean
    public Queue loanRemitStartQueue() {
        return new Queue(TF_WEB_LOAN_REMIT_START);
    }

    @Bean
    public Queue loanRemitUpdateQueue() {
        return new Queue(TF_WEB_LOAN_REMIT_UPDATE);
    }

    @Bean
    public Queue outRemitStartQueue() {
        return new Queue(TF_WEB_OUT_REMIT_START);
    }

    @Bean
    public Queue outRemitUpdateQueue() {
        return new Queue(TF_WEB_OUT_REMIT_UPDATE);
    }

    @Bean
    public Queue repaymentGetInterest() {
        return new Queue(TF_WEB_REPAYMENT_GET_INTEREST);
    }

    @Bean
    public Queue inwardClaimProcess() {
        return new Queue(TF_WEB_INWARD_CLAIM_PROCESS);
    }

    @Bean
    public Queue inwardClaimSingleProcess() {
        return new Queue(TF_WEB_INWARD_CLAIM_SINGLE_PROCESS);
    }

    @Bean
    public Queue repaymentStart() {
        return new Queue(TF_WEB_REPAYMENT_START);
    }

    @Bean
    public Queue repaymentUpdate() {
        return new Queue(TF_WEB_REPAYMENT_UPDATE);
    }

    @Bean
    public Queue transferStart() {
        return new Queue(TF_WEB_TRANSFER_START);
    }

    @Bean
    public Queue transferUpdate() {
        return new Queue(TF_WEB_TRANSFER_UPDATE);
    }

    @Bean
    public Queue riskTradeApply() {
        return new Queue(QUEUE_TRADE_FINANCE_APPLY_MODEL);
    }

    @Bean
    public Queue riskTradeOverdue() {
        return new Queue(QUEUE_TRADE_FINANCE_OVERDUE_NOTIFY);
    }

    @Bean
    public Queue riskTradeRepayment() {
        return new Queue(QUEUE_TRADE_FINANCE_REPAYMENT_NOTIFY);
    }

    @Bean
    public Queue riskMerchant() {
        return new Queue(TRADE_FINANCE_MERCHANT_RISK);
    }
}
